<?php

session_start();

if(!isset($_POST["action"]) && !isset($_POST["retrouver"]) && !isset($_GET["tel"]))
{
	die("404");
}

include_once 'modele/client.class.php';
include_once 'modele/telephone.class.php';

$utilisateur = unserialize($_SESSION['Utilisateur']);

if(isset($_POST["action"]))
{	
	if($_POST["vole"] == "on")
	{
		$vole = true;
	}
	else
	{
		$vole = false;
	}
	
	if($_POST["bloquer"] == "on")
	{
		$bloquer = true;
	}
	else
	{
		$bloquer = false;
	}
	
	if($_POST["sonner"] == "on")
	{
		$sonner = true;
	}
	else
	{
		$sonner = false;
	}
	
	if($_POST["effacer"] == "on")
	{
		$effacer = true;
	}
	else
	{
		$effacer = false;
	}
	
	$utilisateur->telephone[$_GET["tel"]]->volerTelephone($vole, $bloquer, $sonner, $effacer);
	$utilisateur->telephone[$_GET["tel"]]->recupCoord();
}
else if(isset($_POST["retrouver"]))
{
	$utilisateur->telephone[$_GET["tel"]]->retrouverTelephone();
	header("Location:gestTelephone.php?tel="  .$_GET["tel"]);
}
else
{
	$utilisateur->telephone[$_GET["tel"]]->recupCoord();
}

$telephone = $utilisateur->telephone[$_GET["tel"]];
?>

<!DOCTYPE html>
<html>
<head>
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Language" content="fr" />
	
	<link rel="stylesheet" type="text/css" href="css/global.css" />
	<link rel="stylesheet" type="text/css" href="css/telephoneVole.css" />
	
	<script type="text/javascript" src="script/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="script/telephoneVole.js"></script>
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
	
	<script type="text/javascript">
		var lat = <?php print json_encode($telephone->parcoursLat);?>;
		var lng = <?php print json_encode($telephone->parcoursLong);?>;
		var date = <?php print json_encode($telephone->parcoursDate);?>;
	</script>
	
	<title>Contrôle du <?php echo $telephone->numero;?></title>
</head>
<body onload="initialize()">
	<div id='entete'></div>
	<div id='corps'>
		<div id="titre"><h2>Localiser votre téléphone</h2></div>
		<input type="button" onclick="window.location.href='gestTelephone.php?tel=<?php echo $_GET['tel'];?>'" value="Retour">
		<div id="parcoursTel"></div>
	</div>
	<?php 
		$_SESSION['Utilisateur'] = serialize($utilisateur);
	?>
</body>
